<?php


namespace app\cms\dto;


use iflow\Container\implement\annotation\tools\data\NotNull;

class formFieldInfo
{
    protected array $enum = [
        'TEXT' => [
            'type' => 'text',
            'length' => ''
        ],
        'STRING' => [
            'type' => 'varchar',
            'length' => '(255)'
        ],
        'SWITCH' => [
            'type' => 'smallint',
            'length' => ''
        ],
        'BIGINT' => [
            'type' => 'bigint',
            'length' => ''
        ],
        'FLOAT' => [
            'type' => 'float',
            'length' => ''
        ],
        'FILE' => [
            'type' => 'varchar',
            'length' => '(255)'
        ],
        'FILELIST' => [
            'type' => 'text',
            'length' => ''
        ]
    ];


    #[NotNull(error: '模型id不能为空')]
    public int $form_id = 0;
    #[NotNull(error: '模型字段不能为空')]
    public string $form_field_name = '';
    #[NotNull(error: '请选择字段类型')]
    public string $form_field_type = '';
    public int|string $form_field_length = 255;
    #[NotNull(error: '模型字段描述不能为空')]
    public string $form_field_description = "";
    #[NotNull(error: '模型字段默认值不能为空')]
    public string $form_field_default = "";
    #[NotNull(error: '模型字段别名不能为空')]
    public string $form_field_as_name = "";
    public int $status = 1;

    public function getFormFieldType()
    {
        return $this->enum[$this->form_field_type] ?? [
            'type' => $this->form_field_type,
            'length' => $this->getFormFieldLength(),
        ];
    }

    /**
     * @return string
     */
    public function getFormFieldLength(): string
    {
        return "({$this->form_field_length})";
    }
}